package com.qlslylq.ad_x_sdk.comm;

import com.qlslylq.ad.sdk.core.rsp.AdError;
import com.qlslylq.ad.sdk.enums.AdPlatformEnum;
import com.qlslylq.ad.sdk.enums.AdType;
import com.qlslylq.ad.sdk.enums.ErrorEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * created by qlslylq <br/>
 * on 2022/5/23 <br/>
 * 通信(响应)模型<br/>
 */
public class CommRsp extends HashMap<String, Object> {

    public static CommRsp newInstance() {
        return new CommRsp();
    }

    public CommRsp putSuccess() {
        put(CommKey.CODE, ErrorEnum.ERR_SUCCESS.getId());
        put(CommKey.MSG, ErrorEnum.ERR_SUCCESS.getName());
        return this;
    }

    public CommRsp putInitFail(AdPlatformEnum platform, AdType adType, int code, String msg) {
        put(CommKey.CODE, code);
        put(CommKey.MSG, msg);
        put("platform", platform);
        put("adType", adType);
        return this;
    }

    public CommRsp putError(String error) {
        put(CommKey.CODE, ErrorEnum.ERR_FAILD.getId());
        put(CommKey.MSG, ErrorEnum.ERR_FAILD.getName());
        put(CommKey.ERROR, error);
        return this;
    }

    public CommRsp putError(AdError error) {
        Map<String, Object> map = new HashMap<>();
        map.put(CommKey.CODE, error.getCode());
        map.put(CommKey.MSG, error.getMsg());
        map.put("platform", error.getPlatform() + "");
        map.put("adType", error.getAdType() + "");
        put(CommKey.ERROR, map);
        return this;
    }

    public CommRsp putData(Map<String, Object> map) {
        put(CommKey.DATA, map);
        return this;
    }

    public CommRsp putEventName(String eventName) {
        put(CommKey.EVENT_NAME, eventName);
        return this;
    }

    public CommRsp putDislikeValue(String dislikeValue) {
        put(CommKey.DISLIKE_VALUE, dislikeValue);
        return this;
    }

}
